/**
 * @file    WebDocHostUIHandler.cpp
 * @brief   
 * @date    2005-03-15 15:55:23
 * @author  GengYong (gengyong@gmail.com)
 *
 */

#include <cassert>
#include "WebWindowConfig.h"
#include "WebDocHostUIHandler.h"

using namespace xessage_private;

WebDocHostUIHandler::WebDocHostUIHandler(WebWindowImpl * app):m_appImpl(app), m_refCount(1)
{
	m_iDispatcher = new WebExternalDispatcher(app);
	return;
}


WebDocHostUIHandler::~WebDocHostUIHandler()
{
	if (m_iDispatcher != NULL)
	{
		m_iDispatcher->Release();
		m_iDispatcher = NULL;
	}
	return;
}


HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::QueryInterface(REFIID riid, LPVOID * ppvObject)
{
	if (ppvObject == NULL) return E_POINTER;

	if ((riid == IID_IUnknown) 
	 || (riid == IID_IDocHostUIHandler))
	{
		this->AddRef();
		*ppvObject = this;
	}
	else if (riid == IID_IDispatch)
	{
		if (this->m_iDispatcher != NULL)
		{
			this->m_iDispatcher->AddRef();
			*ppvObject = this->m_iDispatcher;
		}
		else
		{
			*ppvObject = 0;
			return(E_NOINTERFACE);
		}
	}
	else
	{
		*ppvObject = 0;
		return(E_NOINTERFACE);
	}
	return S_OK;
}

ULONG STDMETHODCALLTYPE WebDocHostUIHandler::AddRef()
{
	return InterlockedIncrement(&m_refCount);
}

ULONG STDMETHODCALLTYPE WebDocHostUIHandler::Release()
{
	LONG result = InterlockedDecrement(&m_refCount);
	assert(result >= 0);
	if (result == 0)
	{
		delete this;
	}
	return (ULONG)(result);
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::ShowContextMenu(DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
{
#if WEBWINDOW_DISABLEMENU
	return S_OK;
#else
	return E_NOTIMPL;;
#endif
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::GetHostInfo(DOCHOSTUIINFO *pInfo)
{
	if (pInfo != NULL)
	{
		pInfo->cbSize = sizeof(DOCHOSTUIINFO);
		pInfo->dwFlags = WEBWINDOW_STYLE;
		pInfo->dwDoubleClick = WEBWINDOW_DBCLICK;
		pInfo->pchHostCss = NULL;
		pInfo->pchHostNS = NULL;
	}
	return S_OK;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::ShowUI(DWORD dwID, IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget, IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
{
	return E_NOTIMPL;;
}


HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::HideUI( void)
{
	return E_NOTIMPL;;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::UpdateUI( void)
{
	return E_NOTIMPL;;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::EnableModeless(BOOL fEnable)
{
	return E_NOTIMPL;;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::OnDocWindowActivate(BOOL fActivate)
{
	return E_NOTIMPL;;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::OnFrameWindowActivate(BOOL fActivate) 
{
	return E_NOTIMPL;;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::ResizeBorder(LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
{
	return E_NOTIMPL;;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::TranslateAccelerator(LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
{
	return E_NOTIMPL;;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::GetOptionKeyPath(LPOLESTR *pchKey, DWORD dw)
{
	return E_NOTIMPL;;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::GetDropTarget(IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
{
	return E_NOTIMPL;;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::GetExternal(IDispatch **ppDispatch)
{
	if (ppDispatch == NULL) return E_POINTER;

	if (m_iDispatcher != NULL) 
	{
		m_iDispatcher->AddRef();
	}
	*ppDispatch = m_iDispatcher;
	return S_OK;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::TranslateUrl(DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
{
	return E_NOTIMPL;;
}

HRESULT STDMETHODCALLTYPE WebDocHostUIHandler::FilterDataObject(IDataObject *pDO, IDataObject **ppDORet)
{
	return E_NOTIMPL;;
}


